package com.zhugang.week13.program;

/**
 * @program algorithms
 * @description: defangIpaddr
 * @author: chanzhugang
 * @create: 2022/09/11 11:51
 */
public class DefangIpaddr {

    /**
     * 1108 IP地址无效化
     * https://leetcode.cn/problems/defanging-an-ip-address/
     *
     * @param address
     * @return
     */
    public String defangIpaddr(String address) {
        // 动态字符串
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < address.length(); i++) {
            char c = address.charAt(i);
            if (c != '.') {
                sb.append(c);
            } else {
                sb.append("[.]");
            }
        }
        return sb.toString();
    }
}